package com.ccp.dev.core.basic.template;

import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import javax.annotation.Resource;
import java.util.Map;

public class RollbackJdbcTemplate {
    @Resource
    private TransactionTemplate txTemplate;

    public RollbackJdbcTemplate() {
    }

    public Object executeRollBack(final IRollBack rollBack, final String script, final Map<String, Object> map) {
        return this.txTemplate.execute(new TransactionCallback<Object>() {
            @Override
            public Object doInTransaction(TransactionStatus status) {
                Object var2;
                try {
                    var2 = rollBack.execute(script, map);
                } catch (Exception var6) {
                    throw new RuntimeException(var6.getMessage());
                } finally {
                    status.setRollbackOnly();
                }

                return var2;
            }
        });
    }
}
